<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Order_course_auth extends MY_Controller {
	function __construct(){
			parent::__construct();
			$this->load->model('Order_course_auths');
		}
	
	function index($school_id=0,  $limit = 0){
		if($this->input->post()){
			$limit = 0;
			$post_data = $this->input->post('category');
			$school_id = (isset($post_data['school_id'])) ? $post_data['school_id'] : 0;
		}
		$this->load->model('Courses');
		$page_config['uri_segment'] = 4;
		$offset = 10;
		$this->load->model('Goods_courses');
		$school = $this->Goods_courses->get_school();
		$data = array('school_id' => $school_id, 'limit' => $limit);
		$result = $this->Order_course_auths->get_course_list($limit, $offset,$data);
		
		$current_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		$this->load->library('pagination');

		$page_config['base_url'] = '/order_course_auth/index/'.$school_id;
		$page_config['total_rows'] = $result['count'];
		$page_config['per_page'] = $offset;
		$this->pagination->initialize($page_config);
		$pagination = $this->pagination->create_links();
		$this->smarty->assign("data", $data);
		$this->smarty->assign("school", $school);
		$this->smarty->assign("current_url", $current_url);
		$this->smarty->assign("action", "录播课授权");
		$this->smarty->assign("pagination", $pagination);
		$this->smarty->assign("result", $result['result']);
		$this->smarty->display("order_course_auth/list.html"); 
	}
	
	function tiku_list($school_id=0,  $limit = 0){
		if($this->input->post()){
			$limit = 0;
			$post_data = $this->input->post('category');
			$school_id = (isset($post_data['school_id'])) ? $post_data['school_id'] : 0;
		}
		$this->load->model('Courses');
		$page_config['uri_segment'] = 4;
		$offset = 10;
		$this->load->model('Goods_courses');
		$school = $this->Goods_courses->get_school();
		$data = array('school_id' => $school_id, 'limit' => $limit);
		$result = $this->Order_course_auths->get_tiku_list($limit, $offset,$data);
		
		$current_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		$this->load->library('pagination');

		$page_config['base_url'] = '/order_course_auth/index/'.$school_id;
		$page_config['total_rows'] = $result['count'];
		$page_config['per_page'] = $offset;
		$this->pagination->initialize($page_config);
		$pagination = $this->pagination->create_links();
		$this->smarty->assign("data", $data);
		$this->smarty->assign("school", $school);
		$this->smarty->assign("current_url", $current_url);
		$this->smarty->assign("action", "录播课授权");
		$this->smarty->assign("pagination", $pagination);
		$this->smarty->assign("result", $result['result']);
		$this->smarty->display("order_course_auth/list.html"); 
	}

	function shixun_list($school_id=0,  $limit = 0){
		if($this->input->post()){
			$limit = 0;
			$post_data = $this->input->post('category');
			$school_id = (isset($post_data['school_id'])) ? $post_data['school_id'] : 0;
		}
		$this->load->model('Courses');
		$page_config['uri_segment'] = 4;
		$offset = 10;
		$this->load->model('Goods_courses');
		$school = $this->Goods_courses->get_school();
		$data = array('school_id' => $school_id, 'limit' => $limit);
		$result = $this->Order_course_auths->get_shixun_list($limit, $offset, $data);

		$data = json_decode(file_get_contents("http://123.206.137.187:804/HandlerData.ashx?action=GetZhangtaoInfo"),true);
		$shixun_list = array();
		if(!empty($data['rows'])){
			foreach ($data['rows'] as $key => $value) {
				$shixun_list[$value['Id']] = $value;
			}
		}
		$this->smarty->assign("shixun_list", $shixun_list);
		
		$current_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		$this->load->library('pagination');
		$page_config['base_url'] = '/order_course_auth/index/' . $school_id;
		$page_config['total_rows'] = $result['count'];
		$page_config['per_page'] = $offset;
		$this->pagination->initialize($page_config);
		$pagination = $this->pagination->create_links();
		$this->smarty->assign("data", $data);
		$this->smarty->assign("school", $school);
		$this->smarty->assign("current_url", $current_url);
		$this->smarty->assign("action", "录播课授权");
		$this->smarty->assign("pagination", $pagination);
		$this->smarty->assign("result", $result['result']);
		$this->smarty->display("order_course_auth/list.html");
	}

	function school_order_records($record_id = 0, $data_type = 1){
		$this->load->model("Topics");
		$result = $this->Order_course_auths->get_order_record_codes($record_id, $data_type);
		$this->smarty->assign("codes", $result);
		$this->smarty->display("order_course_auth/school_order_records.html");
	}
}